/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.dataset.session;

import java.sql.*;
import nfse.*;

/*******************************************************************************
 * Generic network connection (sessoin) data structure.
 * 
 * @author
 * 
 * This code is the property of Los Alamos National Laboratory and the
 * University of California, Copyright 2005
 */
public abstract class Session extends NetFSERecord {

    /***************************************************************************
     * The destination address as a dot quad (e.g. 1.2.3.4)
     */
    public String dstAddr = "";

    public long dstIP = -1;

    /***************************************************************************
     * The TCP destination port
     */
    public int dstPort = -1;

    /***************************************************************************
     * The TCP source port
     */
    public int srcPort = -1;

    /***************************************************************************
     * The number of packets sent by the destination host
     */
    public long dstPkts = -1;

    /***************************************************************************
     * The number of packets sent by the source host
     */
    public long srcPkts = -1;

    /***************************************************************************
     * The number of bytes sent by the destination host
     */
    public long dstBytes = -1;

    /***************************************************************************
     * The number of bytes sent by the source host
     */
    public long srcBytes = -1;

    protected java.sql.Timestamp stopTS = null;

    /***************************************************************************
     * The protocol identifier for this session
     */
    public int proto = -1;

    public int[] getIndexedFields() {
        int[] temp = { NetFSE.FIELD_START_TS, NetFSE.FIELD_DST_IP, NetFSE.FIELD_SRC_IP, NetFSE.FIELD_DST_PORT };
        return temp;
    }

    /***************************************************************************
     * Return the millisecond portion of this record's start timestamp
     * 
     * @return The milliseconds for this record's start time
     */
    public int getStartMillis() {
        String timeStr = "" + getTimestamp();
        return Integer.parseInt(timeStr.substring(timeStr.length() - 4));
    }

    public Timestamp getStartTS() {
        return this.getTimestamp();
    }

    /***************************************************************************
     * Return the millisecond portion of this record's stop timestamp
     * 
     * @return The milliseconds for this record's end time
     */
    public int getStopMillis() {
        String timeStr = "" + stopTS;
        return Integer.parseInt(timeStr.substring(timeStr.length() - 4));
    }

    public Timestamp getEndTS() {
        return this.stopTS;
    }

    public void setDstIP(long dstIP) {
        this.dstAddr = NetFSEUtil.convertLongToIP(dstIP);
        this.dstIP = dstIP;
    }

    public void setDstPort(int dstPort) {
        this.dstPort = dstPort;
    }

    @Override
    public int getDstPort() {
        return dstPort;
    }

    public void setEndTS(Timestamp stopTS) {
        this.stopTS = stopTS;
    }
    
    @Override
    public long getDstIP() {
        return dstIP;
    }


}